package com.qf.service.Impl;


import com.qf.dao.Impl.UserLoginDaoImpl;
import com.qf.dao.UserLoginDao;
import com.qf.entity.User;
import com.qf.service.UserLoginService;
import com.qf.util.DruidUtil;

public class UserLoginServiceImpl implements UserLoginService {
    UserLoginDao userLoginDao = new UserLoginDaoImpl();

    @Override
    public User userLogin(String username, String password) {
        User user = null;
        user = userLoginDao.selectUser(username);
        if (user != null) {
            if (user.getPassword().equals(password)) {
                return user;
            }
        }
        DruidUtil.close();
        return null;
    }

    @Override
    public int updatePassword(String rePassword, String username) {
        int result = 0;
        try {
            DruidUtil.begin();
            result = userLoginDao.updatePassword(rePassword, username);
            DruidUtil.commit();
        } catch (Exception e) {
            e.printStackTrace();
            DruidUtil.rollback();
        } finally {
            DruidUtil.close();
        }
        return result;
    }
}
